package com.gl.emms.whale.ui;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.gl.emms.client.android.EMMSPushManager;
import com.gl.emms.nio.mutual.ReplyBody;
import com.gl.emms.whale.R;
import com.gl.emms.whale.app.Constant;
import com.gl.emms.whale.app.WhaleMonitorActivity;
import com.gl.emms.whale.util.DialogFactory;
import com.gl.emms.whale.util.SharePreferenceUtil;

public class ValveControlActivity extends WhaleMonitorActivity implements
OnClickListener{
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.activity_valvecontrol);

		Button titleBackBtn = (Button)findViewById(R.id.TitleBackBtn);  
		titleBackBtn.setOnClickListener(new OnClickListener() {  
			public void onClick(View v) {  
				KeyEvent newEvent = new KeyEvent(KeyEvent.ACTION_DOWN,  
						KeyEvent.KEYCODE_BACK);
				finish();
				//mActivity.onKeyDown(KeyEvent.KEYCODE_BACK, newEvent);  
			}  
		});
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}
	public void change_controlmode(View v) {
		CharSequence[] items = { "强制开", "强制关", "强制撤销" };
		controlModeChooseItem(items);
	}

	public void controlModeChooseItem(CharSequence[] items) {
		AlertDialog imageDialog = new AlertDialog.Builder(this)
		.setTitle("选择控制方式")
		.setIcon(android.R.drawable.btn_star)
		.setItems(items, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int item) {
				// 强制开
				if (item == 0) {
					EMMSPushManager.requestForceControl(ValveControlActivity.this,"1-1-1101","1");
				}
				//强制关 
				else if (item == 1) {
					EMMSPushManager.requestForceControl(ValveControlActivity.this,"1-1-1101","2");
				}
				//强制撤销
				else if (item == 2) {
					EMMSPushManager.requestForceControl(ValveControlActivity.this,"1-1-1101","3");
				}
			}
		}).create();

		imageDialog.show();
	}
	@Override
	public void onReplyReceived(final ReplyBody reply) {

		if (reply.getType().equals("forcecontrol_response")) {

			DialogFactory.ToastDialog(ValveControlActivity.this, "控制结果",
					"成功");
		}
	}
}